Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Imports [Gosubb]
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Text
Imports System.Data
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Collections.Generic
Imports System.ComponentModel


Namespace Controls
    Friend Class libGraph
        Inherits Windows.Forms.UserControl

        Private gridData As Double(,)

        Private Const gdPi As Double = 3.14159275180032
        Private Const gdDegreePerRad As Double = 180.0# / gdPi

        Private Const GRID_WIDTH As Integer = 16
        Private Const GRID_HEIGHT As Integer = 16

        Friend WithEvents Direct3DObject As [Gosubb].Direct3d

        Private mwidthScale() As Integer
        Private mheightScale() As Integer

        Private mMainMesh As AutoMesh

        Private mEyeAt As New Vector3(0, 0, 0)
        Private mEyePos As New Vector3(0, 0, -220)

        Sub New()
            InitializeComponent()
            mwidthScale = New Integer() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
            mheightScale = New Integer() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
            LoadData()
            Me.Controls.Add(Me.Direct3DObject)
        End Sub

        Private Sub mD3D_DxLoaded(ByVal d3d As [Gosubb].Direct3d, ByVal dx As Device) Handles Direct3DObject.DxLoaded

            mMainMesh = New AutoMesh(d3d, Mesh.Box(dx, 1, 1, 1))


        End Sub

        Private Sub mD3d_DxRender3d(ByVal d3d As [Gosubb].Direct3d, ByVal dx As Device) Handles Direct3DObject.DxRender3d

            dx.Transform.View = Matrix.LookAtLH(mEyePos, mEyeAt, New Vector3(0, 1, 0))
            dx.Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 4, 1, 1, 20000)
            dx.RenderState.NormalizeNormals = True

        End Sub


        Private Sub LoadData()
            ReDim gridData(GRID_WIDTH - 1, GRID_HEIGHT - 1)
            For y As Integer = 0 To GRID_HEIGHT - 1
                For x As Integer = 0 To GRID_WIDTH - 1
                    gridData(x, y) = (y * x) / 256
                Next
            Next
        End Sub


        Private Sub InitializeComponent()
            Me.Direct3DObject = New [Gosubb].Direct3d
            Me.SuspendLayout()
            '
            'Direct3DObject
            '
            Me.Direct3DObject.DxAutoResize = False
            Me.Direct3DObject.DxFullScreen = False
            Me.Direct3DObject.DxShowCursor = True
            Me.Direct3DObject.Location = New System.Drawing.Point(0, 0)
            Me.Direct3DObject.Name = "Direct3DObject"
            Me.Direct3DObject.Size = New System.Drawing.Size(150, 150)
            Me.Direct3DObject.TabIndex = 0
            '
            'libGraph
            '
            Me.Name = "libGraph"
            Me.Size = New System.Drawing.Size(189, 164)
            Me.ResumeLayout(False)

        End Sub
    End Class
End Namespace